// aisle.cc

#include "aisle.h"
//Returns the Aisle ID
int Aisle::getAisleId(){
  return _aisleId;
}

//Set up aisle with item ids  and quantities
void Aisle::set(int aisleId, int itemIds[]){
  _aisleId = aisleId;
  for(int i=0; i < MAX_ITEMS_PER_AISLE; i++){
    _itemIds[i] = itemIds[i];
    _itemQty[i] = INITIAL_AISLE_ITEM_COUNT;
  }
}

//Restocks one item to the aisle     
bool Aisle::restockItem(int itemId){
  int index = findIndex(itemId);
  //If index was found and Qty lower than 3, incriment qty
  if(index>=0 && _itemQty[index] < 3){
     _itemQty[index] = _itemQty[index] + 1;
     return TRUE;
  }
  else{
    return FALSE;
  }
} 

//Customer picks up one item from the aisle
bool Aisle::pickUpItem(int itemId){
  int index = findIndex(itemId);
  //If index found, and there is at least one item, decriment qty
  if(index>=0 && _itemQty[index] > 0){
    _itemQty[index] = _itemQty[index] - 1;
      return TRUE; 
  }
  else{
      return FALSE;
  }
}

//Prints the aisle stats
void Aisle::printStats(){
  printf("AisleId:%d\n",getAisleId());
  for(int i=0; i<MAX_ITEMS_PER_AISLE; i++){
    printf("\tItemId:%d Qty:%d\n",_itemIds[i],_itemQty[i]);
  }
}

//Index for the Item
int Aisle::findIndex(int itemId){
  int index = -1;
  for (int i=0; i < MAX_ITEMS_PER_AISLE; i++){
    if(_itemIds[i] == itemId){
      index = i;
    }
  }
  return index;
}


